{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{:lang('user')}{:lang('list')}</legend>
    </fieldset>
    <div class="demoTable">
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}关键字">
        </div>
        <div class="layui-inline">
            <input class="layui-input" name="user_id" id="user_id" placeholder="用户id">
        </div>
        <button class="layui-btn" id="search" data-type="reload">搜索</button>
        <a href="{:url('index')}" class="layui-btn">显示全部</a>
        <button type="button" class="layui-btn layui-btn-danger" id="delAll">批量删除</button>
        <div class="layui-inline">
            <select lay-verify="required" style="width: 150px" class="layui-input layui-unselect" id="mobile" >
                <option value='0'>有无联系方式</option>
                <option value='1'>有联系方式</option>
                <option value='2'>无联系方式</option>
            </select>
        </div>
        <div class="layui-inline">
            <select lay-verify="required" style="width: 150px" class="layui-input layui-unselect" id="source_type" >
                <option value='0'>注册方式</option>
                <option value='1'>h5</option>
                <option value='2'>小程序</option>
            </select>
        </div>
        <div class="layui-inline">
        <input id="start_time" type="text" name="start_time" value=" "  placeholder="注册开始时间" class="layui-input">
        </div>
        <div class="layui-inline">
            <input id="end_time" type="text" name="end_time" value=" "  placeholder="注册结束时间" class="layui-input">
        </div>
    </div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
<script type="text/html" id="is_lock">
    <input type="checkbox" name="is_lock" value="{{d.id}}" lay-skin="switch" lay-text="正常|禁用" lay-filter="is_lock" {{ d.is_lock == 0 ? 'checked' : '' }}>
</script>
<script type="text/html" id="action">
    <a href="{:url('edit')}?user_id={{d.user_id}}" class="layui-btn layui-btn-xs">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="email">
    {{d.email}}
    {{# if(d.email && d.email_validated=='0'){ }}
    (未验证)
    {{# } }}
</script>
{include file="common/foot"/}
<script>
    layui.use(['table','form', 'laydate'], function() {
        var table = layui.table,form = layui.form, $ = layui.jquery,laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#start_time'
            , type: 'datetime'
            , format: 'yyyy-MM-dd HH:mm'
        });
        //日期
        laydate.render({
            elem: '#end_time'
            , type: 'datetime'
            , format: 'yyyy-MM-dd HH:mm'
        });
        var tableIn = table.render({
            id: 'user',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            page: true,
            cols: [[
                {checkbox:true,fixed: true},
                {field: 'user_id', title: '用户id', width: 80, fixed: true},
                {field: 'nickname', title: '{:lang("nickname")}', width: 200},
                {field: 'point', title: '积分', width: 150},
                {field: 'mobile', title: '{:lang("tel")}', width: 150},
                {field: 'last_ip', align: 'center',title: '登录ip', width: 180},
                {field: 'province', title: '省份', width: 150},
                {field: 'city', title: '城市', width: 150},
                {field: 'reg_time', title: '注册时间', width: 200},
                {width: 160, align: 'center', toolbar: '#action'}
            ]],
            limit: 10 //每页默认显示的数量
        });
        form.on('switch(is_lock)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var is_lock = obj.elem.checked===true?0:1;
            $.post('{:url("usersState")}',{'id':id,'is_lock':is_lock},function (res) {
                layer.close(loading);
                if (res.status==1) {
                    tableIn.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });
        $('#mobile').on('change', function () {
            var mobile = $(this).val();
            var start_time = $('#start_time').val();
            var end_time = $('#end_time').val();
            var key = $('#key').val();
            var user_id = $('#user_id').val();
            var source_type = $('#source_type').val();
            tableIn.reload({
                where: {mobile: mobile,start_time:start_time,end_time:end_time,key:key,user_id:user_id,source_type:source_type}
            });
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            layer.close(loading);
//            $.post("{:url('index')}", {mobile:mobile,start_time:start_time,end_time:end_time}, function (res) {
//                layer.close(loading);
//
//            });
        });
        $('#source_type').on('change', function () {
            var mobile = $('#mobile').val();
            var key = $('#key').val();
            var user_id = $('#user_id').val();
            var source_type = $(this).val();
            var start_time = $('#start_time').val();
            var end_time = $('#end_time').val();
            tableIn.reload({
                where: {source_type: source_type,start_time:start_time,end_time:end_time,start_time:start_time,mobile:mobile,end_time:end_time}
            });
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            layer.close(loading);
//            $.post("{:url('index')}", {source_type:source_type,start_time:start_time,end_time:end_time}, function (res) {
//                layer.close(loading);
//
//            });
        });
        //搜索
        $('#search').on('click', function() {
            var key = $('#key').val();
            var mobile = $('#mobile').val();
            var user_id = $('#user_id').val();
            var source_type = $('#source_type').val();
            var start_time = $('#start_time').val();
            var end_time = $('#end_time').val();
            tableIn.reload({
                where: {key: key,user_id:user_id,start_time:start_time,end_time:end_time,mobile:mobile,source_type:source_type}
            });
        });

        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('您确定要删除该会员吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('usersDel')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });

        $('#delAll').click(function(){
            layer.confirm('确认要删除选中信息吗？', {icon: 3}, function(index) {
                layer.close(index);
                var checkStatus = table.checkStatus('user'); //test即为参数id设定的值
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('delall')}", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })
    });
</script>
</body>
</html>